package se.webbzon.boltzmann.game.event;

import se.webbzon.boltzmann.debug.Debug;
import se.webbzon.boltzmann.sound.SoundUtils;
import se.webbzon.boltzmann.sound.Sounds;
import se.webbzon.oschi01.worldarea.WorldArea;

public class MusicEvent extends AbstractGameEvent {
	
	// Whatever the music should be looped
	private final boolean loop;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public MusicEvent(String[] arguments, boolean loop) {
		super(arguments);
		this.loop = loop;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override protected void onBegin(WorldArea world) {
		if (arguments() > 0) try {
			Sounds music = Sounds.valueOf(getArgument(0));
			SoundUtils.playSingletonSound(music, loop);
		} catch (IllegalArgumentException e) {
			Debug.report(e);
			SoundUtils.stopSingletonSound();
		} else {
			SoundUtils.stopSingletonSound();
		}
		end();
	}

	@Override protected void onEnd() {};

}
